package com.itheima.service.impl;

import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 套餐业务实现类
 */
@Service
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    private SetmealMapper setmealMapper;

    /**
     * 获取套餐列表
     * @return
     */
    @Override
    public Object getSetmeal() {
        return setmealMapper.getSetmeal();
    }

    /**
     * 根据套餐id查询套餐信息
     * @param id
     * @return
     */
    @Override
    public Object findById(Integer id) {
        Setmeal setmeal = setmealMapper.findSetmealById(id);
        for (CheckGroup checkGroup : setmeal.getCheckGroups()) {
            checkGroup.setCheckItems(setmealMapper.findCheckItemByCheckGroupId(checkGroup.getId()));
        }
        return setmeal;
    }
}
